package net.jescort.repository.impl;

import javax.annotation.Resource;
import net.jescort.domain.user.Email;
import net.jescort.domain.user.User;
import net.jescort.persistence.dao.UserDao;
import net.jescort.repository.UserRepository;
import org.apache.shiro.crypto.hash.Sha256Hash;
import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Service;

/**
 * Created by IntelliJ IDEA. User: Administrator Date: 11-7-14 Time: 下午12:01 To
 * change this template use File | Settings | File Templates.
 */
@Service("userRepository")
@Scope(BeanDefinition.SCOPE_SINGLETON)
public class UserRepositoryImpl implements UserRepository
{
    @Resource(name = "userDao")
    private UserDao userDao;
    
    @Override
    public void createUser(String username, String password, String emailAddress)
    {
        User user = new User();
        user.setUsername(username);
        user.setPassword(new Sha256Hash(password).toHex());
        Email email = new Email(emailAddress);
        user.getEmails().add(email);
        userDao.save(user);
        
    }
}
